package switchviz.core.data;

import java.util.ArrayList;
import java.util.List;


public class Data implements IData
{
	private List<IDataEventListener> _eventHandler = new ArrayList<IDataEventListener>();
	
	private Object _value = null;
	private TimeStamp _timeStamp = null;
	
	public TimeStamp getTimeStamp()
	{
		return _timeStamp;
	}

	public Object getValue()
	{
		return _value;
	}

	public void setValue(Object value, TimeStamp timeStamp)
	{
		_value = value;
		_timeStamp = timeStamp;
		
		for (int i = 0; i < _eventHandler.size(); ++i)
			_eventHandler.get(i).valueChanged(this);
	}
	
	public void addEventListener(IDataEventListener eventListener)
	{
		if (eventListener == null)
			return;
		
		_eventHandler.add(eventListener);
	}
	
	public void removeEventListener(IDataEventListener eventListener)
	{
		_eventHandler.remove(eventListener);
	}
	
	public void removeAllEventListener()
	{
		_eventHandler.clear();
	}
}
